package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {
    /**
     * Spring容器和SpringMVC容器是有层次的（父子容器）
     * Spring容器：service对象+dao对象
     * SpringMVC容器：controller对象，，，，可以引用到Spring容器中的对象
     */
    @Autowired
    private ResumeService resumeService;

    @GetMapping("/index")
    public String index() {
        return "resume";
    }

    @GetMapping("/one")
    @ResponseBody
    public Resume getOne(Long id) {
        return resumeService.getOne(id);
    }

    @GetMapping("/all")
    @ResponseBody
    public List<Resume> all() {
        return resumeService.findAll();
    }

    @PostMapping("/save")
    @ResponseBody
    public void save(@RequestBody Resume resume){
        resumeService.saveOrUpdate(resume);
    }

    @GetMapping("/del")
    @ResponseBody
    public void delete(Long id){
        resumeService.delete(id);
    }

}
